package com.example.testgit.mapstruct;


import com.example.testgit.VO.StudentVO;
import com.example.testgit.entity.StudentDO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.Named;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * @author: lyh
 * @create: 2023/3/27 10:48
 * Description：
 */
@Mapper
public interface StudentConverter{

    StudentConverter INSTANCE = Mappers.getMapper(StudentConverter.class);

    @Mappings({
            @Mapping(source = "eduType", target = "eduType", qualifiedByName = "eduTypeTrans")
    })
    StudentVO toVO(StudentDO studentDO);

    @Mappings({
            @Mapping(source = "eduType", target = "eduType", qualifiedByName = "eduTypeTrans")
    })
    List<StudentVO> toVOList(List<StudentDO> studentDOList);

    @Named("eduTypeTrans")
    default String eduTypeTrans(Integer eduType) {
        if (eduType.equals(1)) return "本科生";
        else if (eduType.equals(2)) return "二学位";
        else if (eduType.equals(3)) return "硕士";
        else return "博士";
    }
}
